<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" :inline="true">
            <el-form-item :label="$t('pinPaiMingCheng')+'：'">
              <el-input v-model="tableFrom.name" :placeholder="$t('qingShuRuPinPaiMingCheng')" clearable >
                <el-button slot="append" icon="el-icon-search" @click="getList()" />
              </el-input>
            </el-form-item>
            <el-form-item :label="$t('bianMa')+'：'">
              <el-input v-model="tableFrom.brandCode" :placeholder="$t('qingShuRuBianMa')" clearable>
                <el-button slot="append" icon="el-icon-search" @click="getList()" />
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="small"
        row-key="brand_id"
        :default-expand-all="false"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column prop="id" label="ID" min-width="60" />
        <el-table-column :label="$t('pinPaiMingCheng')" prop="name" min-width="150" />
        <el-table-column :label="$t('bianMa')" prop="brandCode" min-width="150" />
        <el-table-column :label="$t('fenLeiTuBiao')" min-width="80">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                v-if="scope.row.icon"
                style="width: 36px; height: 36px"
                :src="scope.row.icon"
                :preview-src-list="[scope.row.icon]"
              />
              <img v-else style="width: 36px; height: 36px" :src="defaultImg" alt="">
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="sort" :label="$t('paiXu')" min-width="50" />
        <el-table-column prop="status" :label="$t('shiFouXianShi')" min-width="100">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isShow"
              disabled
              :active-value="true"
              :inactive-value="false"
              :active-text="$t('xianShi')"
              :inactive-text="$t('yinCang')"
            />
          </template>
        </el-table-column>
        <el-table-column prop="createTime" :label="$t('chuangJianShiJian')" min-width="150" />
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import * as storeApi from '@/api/store.js'
import { mapGetters } from 'vuex'
import { checkPermi } from '@/utils/permission' // 权限判断函数
export default {
  name: 'BrandList',
  data() {
    return {
      props: {
        value: 'store_brand_category_id',
        label: 'cate_name',
        children: 'children',
        emitPath: false
      },
      defaultImg: require('@/assets/imgs/moren.jpg'),
      isChecked: false,
      listLoading: true,
      tableData: {
        data: [],
        total: 0
      },
      tableFrom: {
        page: 1,
        limit: 20
      },
      editData: {}
    }
  },
  computed: {
    ...mapGetters(['adminProductClassify'])
  },
  mounted() {
    // this.getBrandCategory();
    if (!this.adminProductClassify.length) this.$store.dispatch('product/getAdminProductClassify')
    this.getList()
  },
  methods: {
    checkPermi,
    // 列表
    getList(num) {
      this.listLoading = true
      this.tableFrom.page = num || this.tableFrom.page
      storeApi
        .brandListApi(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.list
          this.tableData.total = res.total
          // this.tableData.data.map((item) => {
          //   this.imgList.push(item.pic);
          // });
          this.listLoading = false
        })
        .catch((res) => {
          this.listLoading = false
          this.$message.error(res.message)
        })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.selWidth {
  width: 300px !important;
}
</style>
